import 'package:json_annotation/json_annotation.dart';

part 'product_detail.g.dart';

@JsonSerializable()
class ProductDetail {
  final String referStoreId; // 推广店铺
  final List<Option> optionList;
  final Product product; // 商品
  final PDStore store;
  final PDStoreArea storeArea;
  final List<Picture> pictures; // 图片
  final String productModelName; // 商品名称
  final String originPrice; // 原价
  final Price validPrice; // 现价
  final Price validPoints; // 积分
  final Map<String, int> currentSku;
  final List<Sku> skus;
  final Mia defaultMia; // 默认上架
  final List<Mia> allMia;
  final DateTime startTime;
  final DateTime endTime;
  final DateTime serverTime;

  ProductDetail(
    this.referStoreId,
    this.optionList,
    this.product,
    this.store,
    this.storeArea,
    this.pictures,
    this.productModelName,
    this.originPrice,
    this.validPrice,
    this.validPoints,
    this.currentSku,
    this.skus,
    this.defaultMia,
    this.allMia,
    this.startTime,
    this.endTime,
    this.serverTime,
  );

  factory ProductDetail.fromJson(Map<String, dynamic> json) => _$ProductDetailFromJson(json);

  Map<String, dynamic> toJson() => _$ProductDetailToJson(this);
}

@JsonSerializable()
class Option {
  final int id;
  final String name;
  final List<OptionValue> productOptionValues;

  Option(this.id, this.name, this.productOptionValues);

  factory Option.fromJson(Map<String, dynamic> json) => _$OptionFromJson(json);

  Map<String, dynamic> toJson() => _$OptionToJson(this);
}

@JsonSerializable()
class OptionValue {
  final int id;

  final String value;

  OptionValue(this.id, this.value);

  factory OptionValue.fromJson(Map<String, dynamic> json) => _$OptionValueFromJson(json);

  Map<String, dynamic> toJson() => _$OptionValueToJson(this);
}

@JsonSerializable()
class Product {
  final String name;
  final String picture;
  @JsonKey(defaultValue: '')
  final String detail;

  Product(this.name, this.picture, this.detail);

  factory Product.fromJson(Map<String, dynamic> json) => _$ProductFromJson(json);

  Map<String, dynamic> toJson() => _$ProductToJson(this);
}

@JsonSerializable()
class PDStore {
  final int id;

  PDStore(this.id);

  factory PDStore.fromJson(Map<String, dynamic> json) => _$PDStoreFromJson(json);

  Map<String, dynamic> toJson() => _$PDStoreToJson(this);
}

@JsonSerializable()
class PDStoreArea {
  final int id;

  PDStoreArea(this.id);

  factory PDStoreArea.fromJson(Map<String, dynamic> json) => _$PDStoreAreaFromJson(json);

  Map<String, dynamic> toJson() => _$PDStoreAreaToJson(this);
}

@JsonSerializable()
class Picture {
  final String url;

  Picture(this.url);

  factory Picture.fromJson(Map<String, dynamic> json) => _$PictureFromJson(json);

  Map<String, dynamic> toJson() => _$PictureToJson(this);
}

@JsonSerializable()
class Price {
  final String coinType; // RMB、JFB
  final double pointCoin; // 币值额度
  final String pointCoinString; // 币值额度字符串

  Price(this.coinType, this.pointCoin, this.pointCoinString);

  factory Price.fromJson(Map<String, dynamic> json) => _$PriceFromJson(json);

  Map<String, dynamic> toJson() => _$PriceToJson(this);
}

@JsonSerializable()
class Mia {
  final int id;
  final String name;
  final double coinAmount;
  final double pointCoins;

  Mia(this.id, this.name, this.coinAmount, this.pointCoins);

  factory Mia.fromJson(Map<String, dynamic> json) => _$MiaFromJson(json);

  Map<String, dynamic> toJson() => _$MiaToJson(this);
}

@JsonSerializable()
class Sku {
  final int miaId;
  final int stock;
  final Map<String, int> sku;

  Sku(this.miaId, this.stock, this.sku);

  factory Sku.fromJson(Map<String, dynamic> json) => _$SkuFromJson(json);

  Map<String, dynamic> toJson() => _$SkuToJson(this);
}
